package top.abrsm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import top.abrsm.entity.MessageEntity;

import java.util.List;

/**
 * @Author: Wuzh
 * @Description:
 * @Date Created in 17:51 2022-10-16
 * @return
 */
@Mapper
public interface MessageMapper extends BaseMapper<MessageEntity> {

    @Select ( value = "SELECT * FROM message_info mi LEFT JOIN posts_info pi ON mi.postsId = pi.id LEFT JOIN student_info si ON si.id=mi.stuId WHERE mi.notifierId=#{notifierId} AND mi.type=#{type} order by mi.createTime desc limit #{limit},#{offset}" )
    List<MessageEntity> queryList ( String notifierId, Integer type, Integer limit, Integer offset );

    @Select ( value = "SELECT COUNT(1) FROM message_info mi LEFT JOIN posts_info pi ON mi.postsId = pi.id LEFT JOIN student_info si ON si.id=mi.stuId WHERE mi.notifierId=#{notifierId} AND mi.type=#{type}" )
    Integer queryCount ( String notifierId, Integer type );

    @Update ( value = "UPDATE message_info SET isRead=1 WHERE notifierId=#{notifierId} AND type=1" )
    void update ( String notifierId );

}
